package com.ctg.behavior.calc.impala.builder.userlist;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ctg.behavior.calc.impala.report.userlist.CtCalcUGULReport;
import com.ctg.behavior.common.usergroups.CtUGCalcBody;
import com.ctg.behavior.common.userslist.CtULCalcBody;
import com.ctg.behavior.common.userslist.upper.CtUpperUserGroupBody;

@Component
public class CtUGULReportBuilder {

	public CtCalcUGULReport doBuilder(CtUGCalcBody ugCalcBody) {
		CtCalcUGULReport report = new CtCalcUGULReport();
		
		// 不用分页面
		report.setPage(null);
		
		report.setAppId(ugCalcBody.getAppId());
		report.setBookmarkId(ugCalcBody.getBookmarkId());
		report.setRequestId(ugCalcBody.getRequestId());

		report.setId(ugCalcBody.getId());
		report.setName(ugCalcBody.getName());
		report.setPercent(ugCalcBody.getPercent());

		report.setRuleContentList(ugCalcBody.getRuleContentList());
		report.setSortInfo(ugCalcBody.getSortInfo());
		report.setLimit(ugCalcBody.getLimit());

		return report;
	}

	public CtCalcUGULReport doBuilder(CtULCalcBody ulCalcBody) {

		CtCalcUGULReport report = new CtCalcUGULReport();
		
		CtUpperUserGroupBody upperUGBody = null;
		upperUGBody = JSON.parseObject(ulCalcBody.getUpperTaskData(), CtUpperUserGroupBody.class);

		report.setAppId(upperUGBody.getUserGroupBody().getAppId());
		report.setBookmarkId(upperUGBody.getUserGroupBody().getBookmarkId());
		report.setRequestId(upperUGBody.getUserGroupBody().getRequestId());

		report.setId(upperUGBody.getUserGroupBody().getId());
		report.setName(upperUGBody.getUserGroupBody().getName());
		report.setPercent(upperUGBody.getUserGroupBody().getPercent());

		report.setRuleContentList(upperUGBody.getUserGroupBody().getRuleContentList());
		report.setSortInfo(upperUGBody.getUserGroupBody().getSortInfo());
		report.setLimit(upperUGBody.getUserGroupBody().getLimit());
		
		// 分页功能
		report.getPage().setCurrentPage(ulCalcBody.getCurrentPage());
		report.getPage().setLimit(ulCalcBody.getLimit());
		report.getPage().setPageSize(ulCalcBody.getPageSize());
		
		// 用户列表的时间限制
		report.setFromDate(ulCalcBody.getFromDate());
		report.setToDate(ulCalcBody.getToDate());
		report.setUnit(ulCalcBody.getUnit());
		
		// SELECT中的用户属情字段
		report.setProfiles(ulCalcBody.getProfiles());
		
		// 升序 或 降序
		report.getSortInfo().setSortProfile(ulCalcBody.getSortByField());
		report.getSortInfo().setSortAsc(ulCalcBody.getAsc());

		return report;

	}

}
